# -*- coding: utf-8 -*-
# @Time        :2025/8/5 下午2:19
# @Author      :文刀水寿
# @File        : 创建gevent.py
"""
 @Description :
"""
import time

import gevent
from gevent import monkey

# def work1():
#     while True:
#         print("--work1--")
#         yield
#         time.sleep(0.5)
#
#
# def work2():
#     while True:
#         print("--work2--")
#         yield
#         time.sleep(0.5)
#
# def main():
#     w1 = work1()
#     w2 = work2()
#     while True:
#         next(w1)
#         next(w2)
#
# if __name__ == '__main__':
#     main()

monkey.patch_all()


def f(n) -> None:
    for i in range(n):
        print(f"-----{i}")
        # gevent.sleep(1)
        time.sleep(1)  # 对time打补丁 monkey  可以实现time.sleep 和gevent.sleep相同的效果
        # 可以切换也可以等待


g1 = gevent.spawn(f, 5)
g2 = gevent.spawn(f, 5)
g3 = gevent.spawn(f, 5)
g1.join()
g2.join()
g3.join()
